MAIN.controller('compareCtrl', ["$scope", "$rootScope", "tools", "$http", function ($scope, $rootScope, tools) {
    $scope.switchType = function (type) {
        $rootScope.$broadcast('switchType', type);
    }
    $rootScope.$broadcast('switchType', 'town');
    $scope.topSalers = [];
    if (!tools.datasource) {
        // data =
        tools.get({
            url: '/Intelligence-Business-Management/getDatasByModuleId.htm',
            data: {
                uuid: '69341649-c33d-4fd3-b6d1-7d264df7c8b0',
                moduleId: '1716110043335',
                moduleType: 'data',
                sortType: 'desc',
                sortField: 'doub4',
                beginIndex: 0,
                resultSize: 27
            },
            succ: function (resp) {
                if (resp.success) {
                    var size = resp.value.datas[0].length;
                    for (var i = 1; i < resp.value.datas.length; i++) {
                        $scope.topSalers.push({
                            name: resp.value.datas[i][0],
                            saleMoney: resp.value.datas[i][1],
                            saleMount: resp.value.datas[i][2],
                            perPrice: resp.value.datas[i][3],
                            town: resp.value.datas[i][4],
                            village: resp.value.datas[i][5]
                        });
                    }
                }
            }
        });
    } else {
        tools.get({
            url: '/Intelligence-Business-Management/getDatasByModuleId.htm',
            data: {
                uuid: '69341649-c33d-4fd3-b6d1-7d264df7c8b0',
                // moduleId: '881621414522',
                moduleId: '1716110043335',
                moduleType: 'data',
                sortType: 'desc',
                sortField: 'doub4'
                // requestSequence: 0,
                // sortType: 'desc',
                // sortField: 'doub2',
                // resultSize: 27
            },
            succ: function (resp) {
                if (resp.success) {
                    // var size = resp.value.datas[0].length;
                    // for (var i = 1; i < size; i++) {
                    //     $scope.topSalers.push({
                    //         name: resp.value.datas[0][i],
                    //         saleMoney: resp.value.datas[2][i],
                    //         saleMount: resp.value.datas[3][i],
                    //         perPrice: resp.value.datas[1][i],
                    //     });
                    // }
                    for (var i = 1; i < resp.value.datas.length; i++) {
                        $scope.topSalers.push({
                            name: resp.value.datas[i][0],
                            saleMoney: resp.value.datas[i][1],
                            saleMount: resp.value.datas[i][2],
                            perPrice: resp.value.datas[i][3],
                            town: resp.value.datas[i][4],
                            village: resp.value.datas[i][5]
                        });
                    }
                }
            }
        });
    }
    // tools.get({
    //     url: '/Intelligence-Business-Management/getDatasByModuleId.htm',
    //     data: {
    //         uuid: '69341649-c33d-4fd3-b6d1-7d264df7c8b0',
    //         moduleId: '881621414522',
    //         requestSequence: 0,
    //         sortType: 'desc',
    //         sortField: 'doub2',
    //         resultSize: 30
    //     },
    //     succ: function (resp) {
    //         if (resp.success) {
    //             var size = resp.value.datas[0].length;
    //             for (var i = 1; i < 30; i++) {
    //                 $scope.topSalers.push({
    //                     name: resp.value.datas[0][i],
    //                     saleMoney: resp.value.datas[2][i],
    //                     saleMount: resp.value.datas[3][i],
    //                     perPrice: resp.value.datas[1][i],

    //                 });
    //             }
    //         }
    //     }
    // });
}]);
//2016年本县店铺总数统计
MAIN.directive("shopsNumChart", ["$rootScope", "tools", function ($rootScope, tools) {
    return {
        restrict: 'AE',
        scope: {},
        replace: true,
        link: function (scope, element, attrs) {
            var chart_ele = document.getElementById("ShopNumChart");
            var ShopNumChart = echarts.init(chart_ele, theme);
            var option;

            if (tools.datasource) {
                tools.get({
                    url: '/Intelligence-Business-Management/getChartByModuleId.htm',
                    data: {
                        uuid: '69341649-c33d-4fd3-b6d1-7d264df7c8b0',
                        moduleId: 1316113035450,
                        moduleType: 'chart'
                    },
                    succ: function (resp) {
                        if (resp.success) {
                            option = resp.value.option;
                            option.title = {
                                text: '2016年' + tools.town() + '县各镇店铺总数统计',
                                x: 'left'
                            };
                            option.legend = {
                                x: 'right',
                                y: 'top',
                                data: resp.value.option.legend.data
                            }
                            option.yAxis = [
                                {
                                    type: 'value',
                                    axisLabel: {
                                        textStyle: {
                                            color: '#fff'
                                        }
                                    }
                                }
                            ];
                            angular.forEach(option.xAxis[0].data, function (item, index) {
                                option.xAxis[0].data[index] = {value: item, textStyle: {color: '#fff'}};
                            });
                            option.toolbox.show = false;
                            option.series[0].itemStyle = {};
                            ShopNumChart.setOption(option);
                        }
                    }
                });
            } else {
                option = {
                    title: {
                        text: '2016年' + tools.town() + '县各镇店铺总数统计',
                        subtext: '',
                        x: 'left'
                    },
                    legend: {
                        data: ['淘宝', '天猫', '京东', '1688', '苏宁'],
                        x: 'right'
                    },
                    tooltip: {
                        trigger: 'axis'
                    },
                    toolbox: {
                        show: false
                    },
                    xAxis: [
                        {
                            type: 'value',
                            axisLabel: {
                                textStyle: {
                                    color: '#fff'
                                }
                            }
                        }
                    ],
                    yAxis: [
                        {
                            type: 'category',
                            axisLabel: {
                                textStyle: {
                                    color: '#fff'
                                }
                            },
                            data: tools.towns().slice(0, 6)
                        }
                    ],
                    series: [
                        {
                            name: '淘宝',
                            type: 'bar',
                            stack: '总量',
                            itemStyle: {normal: {label: {show: true, position: 'insideRight'}}},
                            data: [35, 40, 43, 45, 46, 48, 53]
                        },
                        {
                            name: '天猫',
                            type: 'bar',
                            stack: '总量',
                            itemStyle: {normal: {label: {show: true, position: 'insideRight'}}},
                            data: [3, 15, 3, 2, 5, 3, 6]
                        },
                        {
                            name: '京东',
                            type: 'bar',
                            stack: '总量',
                            itemStyle: {normal: {label: {show: true, position: 'insideRight'}}},
                            data: [2, 4, 15, 2, 4, 4, 6]
                        },
                        {
                            name: '1688',
                            type: 'bar',
                            stack: '总量',
                            itemStyle: {normal: {label: {show: true, position: 'insideRight'}}},
                            data: [3, 6, 2, 8, 9, 2, 7]
                        },
                        {
                            name: '苏宁',
                            type: 'bar',
                            stack: '总量',
                            itemStyle: {normal: {label: {show: true, position: 'insideRight'}}},
                            data: [1, 2, 3, 2, 2, 3, 8]
                        }
                    ]
                };
                ShopNumChart.setOption(option);
                ShopNumChart.on(echarts.config.EVENT.CLICK, function (param) {
                    console.log(param.name);
                    option.title.text = '2016年' + param.name + '各村店铺总数统计';
                    option.yAxis[0].data = tools.villages().slice(0, 6);
                    angular.forEach(option.series, function (item) {
                        angular.forEach(item.data, function (item, index, array) {
                            array[index] = array[index] += (Math.floor(Math.random() * 20));
                        });
                    });
                    ShopNumChart.setOption(option);
                    /*option.title.text = '2016年' + param.name + '各村平均发单时间统计';
                     option.xAxis = [
                     {
                     type: 'category',
                     data: tools.villages().slice(0, 6),
                     axisLabel: {
                     textStyle: {
                     color: '#fff'
                     }
                     }
                     }
                     ];
                     option.series[0].data = datas.village;*/
                    ShopNumChart.setOption(option);
                });
            }
            ;


            $rootScope.$on('switchType', function (e, type) {
                if (type == 'town') {
                    option.yAxis[0].data = tools.towns().slice(0, 6);
                } else if (type == 'village') {
                    option.yAxis[0].data = tools.villages().slice(0, 6);
                } else {
                    option.yAxis[0].data = tools.industrys().slice(0, 6);
                }
                angular.forEach(option.series, function (val) {
                    angular.forEach(val.data, function (vall, index) {
                        val.data[index] += Math.floor(Math.random() * 10);
                    });
                });
                ShopNumChart.setOption(option);
            });
            scope.fullscreen = function () {
                $rootScope.$broadcast('fullscreen', option);
            }
        },
        template: '<div class="w h"><div id = "ShopNumChart" class="w h"></div><div class = "full-screen right-bottom-pos" ng-click = "fullscreen()"></div></div>'
    }
}]);
//2016年本县电子商务从业人数统计
MAIN.directive("peoplesNumChart", ["$rootScope", "tools", function ($rootScope, tools) {
    return {
        restrict: 'AE',
        scope: {},
        replace: true,
        link: function (scope, element, attrs) {
            var chart_ele = document.getElementById("peopleNumChart");
            var peopleNumChart = echarts.init(chart_ele, theme), option;
            if (tools.datasource) {
                tools.get({
                    url: '/Intelligence-Business-Management/getChartByModuleId.htm',
                    data: {
                        uuid: '69341649-c33d-4fd3-b6d1-7d264df7c8b0',
                        moduleId:1316113040513,
                        moduleType:'chart'
                    },
                    succ: function (resp) {
                        if (resp.success) {
                            option = resp.value.option;
                            option.title = {
                                text: '2016年' + tools.town() + '县各镇电子商务从业人数统计',
                                x: 'center'
                            };
                            option.yAxis = [
                                {
                                    type: 'value',
                                    axisLabel: {
                                        textStyle: {
                                            color: '#fff'
                                        }
                                    }
                                }
                            ];
                            angular.forEach(option.xAxis[0].data, function (item, index) {
                                option.xAxis[0].data[index] = {value: item, textStyle: {color: '#fff'}};
                            });
                            option.toolbox.show = false;
                            option.legend.show = false;
                            option.series[0].itemStyle = {};
                            peopleNumChart.setOption(option);
                        }
                    }
                });
                // option = {
                //     title: {
                //         text: '2016年' + tools.town() + '县各镇电子商务从业人数统计',
                //         x: 'left'
                //     },
                //     tooltip: {
                //         trigger: 'axis'
                //     },
                //     calculable: true,
                //     xAxis: [
                //         {
                //             type: 'category',
                //             // data: tools.towns().slice(0, 6),
                //             data: ["{未知}", "{上屯镇}", "{东王集乡}", "{古城乡}", "{城郊乡}", "{大河屯镇}", "{张店镇}", "{昝岗乡}", "{桐寨铺镇}", "{桐河乡}", "{毕店镇}", "{湖阳镇}", "{源潭镇}", "{祁仪乡}", "{苍台镇}", "{郭滩镇}", "{马振抚乡}", "{黑龙镇}", "{龙潭镇}"],
                //             axisLabel: {
                //                 textStyle: {
                //                     color: '#fff'
                //                 }
                //             }
                //         }
                //     ],
                //     yAxis: [
                //         {
                //             type: 'value',
                //             axisLabel: {
                //                 textStyle: {
                //                     color: '#fff'
                //                 }
                //             }
                //         }
                //     ],
                //     series: [
                //         {
                //             name: '人数',
                //             type: 'bar',
                //             // data: [22, 29, 34, 56, 68, 57, 29],
                //             data: [3134, 756, 108, 540, 2053, 540, 216, 973, 1729, 216, 2378, 865, 432, 324, 757, 540, 216, 648],
                //             markPoint: {
                //                 data: [
                //                     {type: 'max', name: '最大值'},
                //                     {type: 'min', name: '最小值'}
                //                 ]
                //             },
                //             markLine: {
                //                 data: [
                //                     {type: 'average', name: '平均值'}
                //                 ]
                //             }
                //         }
                //     ]
                // };

                // peopleNumChart.setOption(option);
            } else {
                option = {
                    title: {
                        text: '2016年' + tools.town() + '县各镇电子商务从业人数统计',
                        x: 'left'
                    },
                    tooltip: {
                        trigger: 'axis'
                    },
                    calculable: true,
                    xAxis: [
                        {
                            type: 'category',
                            data: tools.towns().slice(0, 6),
                            axisLabel: {
                                textStyle: {
                                    color: '#fff'
                                }
                            }
                        }
                    ],
                    yAxis: [
                        {
                            type: 'value',
                            axisLabel: {
                                textStyle: {
                                    color: '#fff'
                                }
                            }
                        }
                    ],
                    series: [
                        {
                            name: '人数',
                            type: 'bar',
                            data: [22, 29, 34, 56, 68, 57, 29],
                            markPoint: {
                                data: [
                                    {type: 'max', name: '最大值'},
                                    {type: 'min', name: '最小值'}
                                ]
                            },
                            markLine: {
                                data: [
                                    {type: 'average', name: '平均值'}
                                ]
                            }
                        }
                    ]
                };

                peopleNumChart.setOption(option);
            }


            peopleNumChart.on(echarts.config.EVENT.CLICK, function (param) {
                option.title.text = '2016年' + param.name + '各村平均发单时间统计';
                option.xAxis = [
                    {
                        type: 'category',
                        data: tools.villages().slice(0, 6),
                        axisLabel: {
                            textStyle: {
                                color: '#fff'
                            }
                        }
                    }
                ];
                angular.forEach(option.series[0].data, function (item, index, array) {
                    array[index] += (Math.floor(Math.random() * 10));
                });
                //option.series[0].data = datas.village;
                peopleNumChart.setOption(option);
            });

            $rootScope.$on('switchType', function (e, type) {
                if (type == 'town') {
                    option.xAxis[0].data = tools.towns().slice(0, 6);
                } else if (type == 'village') {
                    option.xAxis[0].data = tools.villages().slice(0, 6);
                } else {
                    option.xAxis[0].data = tools.industrys().slice(0, 6);
                }
                /*angular.forEach(option.series[0], function (val) {
                 angular.forEach(val.data, function (vall, index) {
                 val.data[index] += Math.floor(Math.random() * 10);
                 });
                 });*/
                angular.forEach(option.series[0].data, function (v, i, arr) {
                    arr[i] += Math.floor(Math.random() * 300);
                });
                peopleNumChart.setOption(option);
            });
            scope.fullscreen = function () {
                $rootScope.$broadcast('fullscreen', option);
            }
        },
        template: '<div class="w h"><div id = "peopleNumChart" class="w h"></div><div class = "full-screen right-bottom-pos" ng-click = "fullscreen()"></div></div>'
    }
}]);
//2016年本县各镇电子商务季度成交额统计
MAIN.directive("yearsTurnoverChart", ["$rootScope", "tools", function ($rootScope, tools) {
    return {
        restrict: 'AE',
        scope: {},
        replace: true,
        link: function (scope, element, attrs) {
            var option;
            var chart_ele = document.getElementById("YearTurnoverChart");
            var YearTurnoverChart = echarts.init(chart_ele, theme);
            if(tools.datasource) {
                tools.get({
                    url: '/Intelligence-Business-Management/getChartByModuleId.htm',
                    data: {
                        uuid: '69341649-c33d-4fd3-b6d1-7d264df7c8b0',
                        moduleId:1316113035050,
                        moduleType:'chart'
                    },
                    succ: function (resp) {
                        if (resp.success) {

                            option = resp.value.option;
                            // option.series = [];
                            resp.value.option.series.length = 5
                            option.title = {
                                text: '2016' + tools.town() + '县五强镇电子商务季度成交额统计',
                                x: 'center'
                            };
                            option.yAxis = [
                                {
                                    type: 'value',
                                    axisLabel: {
                                        textStyle: {
                                            color: '#fff'
                                        }
                                    }
                                }
                            ];
                            option.xAxis[0].data = ['{2016}-{1}','{2016}-{2}'];

                            option.legend.data.length = 5;
                            
                            angular.forEach(option.xAxis[0].data, function (item, index) {
                                option.xAxis[0].data[index] = {value: item, textStyle: {color: '#fff'}};
                                
                            });
                            option.toolbox.show = false;
                            option.legend.show = false;
                          
                            YearTurnoverChart.setOption(option);
                        }
                    }
                });
            } else {
                // option = {
                //     title: {
                //         text: '2016' + tools.town() + '县五强镇电子商务季度成交额统计',
                //         x: 'left'
                //     },
                //     tooltip: {
                //         trigger: 'axis'
                //     },
                //     legend: {
                //         data: tools.towns().slice(0, 5),
                //         x: 'right'
                //     },
                //     calculable: true,
                //     xAxis: [
                //         {
                //             type: 'category',
                //             boundaryGap: false,
                //             data: ['2014年第一季度', '2014年第二季度', '2014年第三季度', '2014年第四季度', '2016年第一季度', '2016年第二季度', '2016年第三季度', '2016年第四季度'],
                //             axisLabel: {
                //                 textStyle: {
                //                     color: '#fff'
                //                 }
                //             }
                //         }
                //     ],
                //     yAxis: [
                //         {
                //             type: 'value',
                //             name: '单位:(万元)',
                //             axisLabel: {
                //                 textStyle: {
                //                     color: '#fff'
                //                 }
                //             }

                //         }
                //     ],
                //     series: [
                //         {
                //             name: tools.towns()[0],
                //             type: 'line',
                //             data: [102.3, 112.4, 120.4, 200.36, 162.3, 177.4, 180.3, 263.3],
                //             markPoint: {
                //                 data: [
                //                     {type: 'max', name: '最大值(双十一双十二)'},
                //                     {type: 'min', name: '最小值'}
                //                 ]
                //             },
                //             markLine: {
                //                 data: [
                //                     {type: 'average', name: '平均值'}
                //                 ]
                //             },
                //             markPoint: {
                //                 data: [
                //                     {type: 'max', name: '最大值(双十一双十二)'},
                //                     {type: 'min', name: '最小值'},
                //                     {name: '双十一双十二', value: 11, xAxis: '2014年第四季度', yAxis: 11, symbolSize: 18}
                //                 ]
                //             },
                //         },
                //         {
                //             name: tools.towns()[1],
                //             type: 'line',
                //             data: [85.36, 96.33, 102.36, 160.23, 140.22, 145.36, 147.3, 150.2],
                //             markLine: {
                //                 data: [
                //                     {type: 'average', name: '平均值'}
                //                 ]
                //             },
                //             markPoint: {
                //                 data: [
                //                     {type: 'max', name: '最大值(双十一双十二)'},
                //                     {type: 'min', name: '最小值'},
                //                     {name: '双十一双十二', value: 10, xAxis: '2014年第四季度', yAxis: 10, symbolSize: 18}
                //                 ]
                //             },
                //         },
                //         {
                //             name: tools.towns()[2],
                //             type: 'line',
                //             data: [69.3, 75.2, 80.26, 150.3, 99.3, 101.36, 113.4, 185.3],
                //             markLine: {
                //                 data: [
                //                     {type: 'average', name: '平均值'}
                //                 ]
                //             },
                //             markPoint: {
                //                 data: [
                //                     {type: 'max', name: '最大值(双十一双十二)'},
                //                     {type: 'min', name: '最小值'},
                //                     {name: '双十一双十二', value: 9, xAxis: '2014年第四季度', yAxis: 9, symbolSize: 18}
                //                 ]
                //             },
                //         },
                //         {
                //             name: tools.towns()[3],
                //             type: 'line',
                //             data: [29.3, 69.2, 75.26, 104.3, 109.3, 113.36, 133.4, 185.3],
                //             markLine: {
                //                 data: [
                //                     {type: 'average', name: '平均值'}
                //                 ]
                //             },
                //             markPoint: {
                //                 data: [
                //                     {type: 'max', name: '最大值(双十一双十二)'},
                //                     {type: 'min', name: '最小值'},
                //                     {name: '双十一双十二', value: 9, xAxis: '2014年第四季度', yAxis: 9, symbolSize: 18}
                //                 ]
                //             },
                //         },
                //         {
                //             name: tools.towns()[4],
                //             type: 'line',
                //             data: [49.3, 69.2, 85.26, 94.3, 102.3, 119.36, 166.4, 189.3],
                //             markLine: {
                //                 data: [
                //                     {type: 'average', name: '平均值'}
                //                 ]
                //             },
                //             markPoint: {
                //                 data: [
                //                     {type: 'max', name: '最大值(双十一双十二)'},
                //                     {type: 'min', name: '最小值'},
                //                     {name: '双十一双十二', value: 9, xAxis: '2014年第四季度', yAxis: 9, symbolSize: 18}
                //                 ]
                //             }
                //         }
                //     ]
                // };
                option = {
                    title: {
                        text: '2016' + tools.town() + '县五强镇电子商务季度成交额统计',
                        x: 'left'
                    },
                    tooltip: {
                        trigger: 'axis'
                    },
                    legend: {
                        data: tools.towns().slice(0, 5),
                        x: 'right'
                    },
                    calculable: true,
                    xAxis: [
                        {
                            type: 'category',
                            boundaryGap: false,
                            data: ['2014年第一季度', '2014年第二季度', '2014年第三季度', '2014年第四季度', '2016年第一季度', '2016年第二季度', '2016年第三季度', '2016年第四季度'],
                            axisLabel: {
                                textStyle: {
                                    color: '#fff'
                                }
                            }
                        }
                    ],
                    yAxis: [
                        {
                            type: 'value',
                            name: '单位:(万元)',
                            axisLabel: {
                                textStyle: {
                                    color: '#fff'
                                }
                            }

                        }
                    ],
                    series: [
                        {
                            name: tools.towns()[0],
                            type: 'line',
                            // data: [102.3, 112.4, 120.4, 200.36, 162.3, 177.4, 180.3, 263.3],
                            data: [15.3, 16.4, 17.4, 25.36, 20.3, 21.4, 22.3, 31.3],
                            markPoint: {
                                data: [
                                    {type: 'max', name: '最大值(双十一双十二)'},
                                    {type: 'min', name: '最小值'}
                                ]
                            },
                            markLine: {
                                data: [
                                    {type: 'average', name: '平均值'}
                                ]
                            },
                            markPoint: {
                                data: [
                                    {type: 'max', name: '最大值(双十一双十二)'},
                                    {type: 'min', name: '最小值'},
                                    {name: '双十一双十二', value: 25.36, xAxis: '2014年第四季度', yAxis: 25.36, symbolSize: 18}
                                ]
                            },
                        },
                        {
                            name: tools.towns()[1],
                            type: 'line',
                            // data: [85.36, 96.33, 102.36, 160.23, 140.22, 145.36, 147.3, 150.2],
                            data: [13.36, 14.33, 15.36, 21.23, 19.22, 19.36, 19.3, 20.2],
                            markLine: {
                                data: [
                                    {type: 'average', name: '平均值'}
                                ]
                            },
                            markPoint: {
                                data: [
                                    {type: 'max', name: '最大值(双十一双十二)'},
                                    {type: 'min', name: '最小值'},
                                    {name: '双十一双十二', value: 21.23, xAxis: '2014年第四季度', yAxis: 21.23, symbolSize: 18}
                                ]
                            },
                        },
                        {
                            name: tools.towns()[2],
                            type: 'line',
                            // data: [69.3, 75.2, 80.26, 150.3, 99.3, 101.36, 113.4, 185.3],
                            data: [11.3, 12.2, 13.26, 20.3, 14.3, 15.36, 16.4, 23.3],
                            markLine: {
                                data: [
                                    {type: 'average', name: '平均值'}
                                ]
                            },
                            markPoint: {
                                data: [
                                    {type: 'max', name: '最大值(双十一双十二)'},
                                    {type: 'min', name: '最小值'},
                                    {name: '双十一双十二', value: 20.3, xAxis: '2014年第四季度', yAxis: 20.3, symbolSize: 18}
                                ]
                            },
                        },
                        {
                            name: tools.towns()[3],
                            type: 'line',
                            // data: [29.3, 69.2, 75.26, 104.3, 109.3, 113.36, 133.4, 185.3],
                            data: [14.3, 14.2, 13.26, 15.3, 15.3, 16.36, 18.4, 23.3],
                            markLine: {
                                data: [
                                    {type: 'average', name: '平均值'}
                                ]
                            },
                            markPoint: {
                                data: [
                                    {type: 'max', name: '最大值(双十一双十二)'},
                                    {type: 'min', name: '最小值'},
                                    {name: '双十一双十二', value: 15.3, xAxis: '2014年第四季度', yAxis: 15.3, symbolSize: 18}
                                ]
                            },
                        },
                        {
                            name: tools.towns()[4],
                            type: 'line',
                            // data: [49.3, 69.2, 85.26, 94.3, 102.3, 119.36, 166.4, 189.3],
                            data: [9.3, 11.2, 13.26, 14.3, 15.3, 16.36, 21.4, 23.3],
                            markLine: {
                                data: [
                                    {type: 'average', name: '平均值'}
                                ]
                            },
                            markPoint: {
                                data: [
                                    {type: 'max', name: '最大值(双十一双十二)'},
                                    {type: 'min', name: '最小值'},
                                    {name: '双十一双十二', value: 14.3, xAxis: '2014年第四季度', yAxis: 14.3, symbolSize: 18}
                                ]
                            }
                        }
                    ]
                };
                YearTurnoverChart.setOption(option);
            }
            // YearTurnoverChart.setOption(option);


            $rootScope.$on('switchType', function (e, type) {
                if (type == 'town') {
                    option.series[0].name = tools.towns()[0];
                    option.series[1].name = tools.towns()[1];
                    option.series[2].name = tools.towns()[2];
                } else if (type == 'village') {
                    option.series[0].name = tools.villages()[0];
                    option.series[1].name = tools.villages()[1];
                    option.series[2].name = tools.villages()[2];
                } else {
                    option.series[0].name = tools.industrys()[0];
                    option.series[1].name = tools.industrys()[1];
                    option.series[2].name = tools.industrys()[2];
                }
                /*angular.forEach(option.series, function (ser) {
                 angular.forEach(ser.data, function (val, index) {
                 ser.data[index] += Number(Math.random().toFixed(1));
                 });
                 });*/
                YearTurnoverChart.setOption(option);
            });
            scope.fullscreen = function () {
                option.legend.show = true;
                option.title.show = false;
                $rootScope.$broadcast('fullscreen', option);

            }
        },
        template: '<div class="w h"><div id = "YearTurnoverChart" class="w h"></div><div class = "full-screen right-bottom-pos" ng-click = "fullscreen()"></div></div>'
    }
}]);
//2016年本县各镇电子商务店铺平均情况统计
MAIN.directive("averagesPraiseChart", ["$rootScope", "tools", function ($rootScope, tools) {
    return {
        restrict: 'AE',
        scope: {},
        replace: true,
        link: function (scope, element, attrs) {
            var option = {
                legend: {
                    x: 'right',
                    y: 'top',
                    data: [
                        '好评率', '转化率', '退款率', '差评率'
                    ]
                },
                title: {
                    text: '2016' + tools.town() + '县各镇店铺平均情况统计',
                    x: 'left'
                },
                series: [
                    {
                        type: 'pie',
                        center: ['10%', '50%'],
                        radius: [40, 60],
                        x: '0%',
                        itemStyle: {
                            normal: {
                                label: {
                                    formatter: function (params) {
                                        return 100 - params.value + '%'
                                    },
                                    textStyle: {
                                        baseline: 'top'
                                    }
                                }
                            },
                        },
                        data: [
                            {
                                name: 'other',
                                value: 0.5,
                                itemStyle: {
                                    normal: {
                                        color: '#ccc',
                                        label: {
                                            show: true,
                                            position: 'center'
                                        },
                                        labelLine: {
                                            show: false
                                        }
                                    },
                                    emphasis: {
                                        color: 'rgba(0,0,0,0)'
                                    }
                                }
                            },
                            {
                                name: '好评率',
                                value: 99.5,
                                itemStyle: {
                                    normal: {
                                        label: {
                                            show: true,
                                            position: 'center',
                                            formatter: '{b}',
                                            textStyle: {
                                                baseline: 'bottom'
                                            }
                                        },
                                        labelLine: {
                                            show: false
                                        }
                                    }
                                }

                            }
                        ]
                    },
                    {
                        type: 'pie',
                        center: ['30%', '50%'],
                        radius: [40, 60],
                        x: '20%', // for funnel
                        itemStyle: {
                            normal: {
                                label: {
                                    formatter: function (params) {
                                        return 100 - params.value + '%'
                                    },
                                    textStyle: {
                                        baseline: 'top'
                                    }
                                }
                            },
                        },
                        data: [
                            {
                                name: 'other',
                                value: 85,
                                itemStyle: {
                                    normal: {
                                        color: '#1bb2d8',
                                        label: {
                                            show: true,
                                            position: 'center'
                                        },
                                        labelLine: {
                                            show: false
                                        }
                                    },
                                    emphasis: {
                                        color: 'rgba(0,0,0,0)'
                                    }
                                }
                            },
                            {
                                name: '转化率',
                                value: 15,
                                itemStyle: {
                                    normal: {
                                        label: {
                                            show: true,
                                            position: 'center',
                                            formatter: '{b}',
                                            textStyle: {
                                                baseline: 'bottom'
                                            }
                                        },
                                        labelLine: {
                                            show: false
                                        }
                                    }
                                }

                            }
                        ]
                    },
                    {
                        type: 'pie',
                        center: ['50%', '50%'],
                        radius: [40, 60],
                        x: '40%', // for funnel
                        itemStyle: {
                            normal: {
                                label: {
                                    formatter: function (params) {
                                        return 100 - params.value + '%'
                                    },
                                    textStyle: {
                                        baseline: 'top'
                                    }
                                }
                            },
                        },
                        data: [
                            {
                                name: 'other',
                                value: 95,
                                itemStyle: {
                                    normal: {
                                        color: '#1bb2d8',
                                        label: {
                                            show: true,
                                            position: 'center'
                                        },
                                        labelLine: {
                                            show: false
                                        }
                                    },
                                    emphasis: {
                                        color: 'rgba(0,0,0,0)'
                                    }
                                }
                            },
                            {
                                name: '退款率',
                                value: 5,
                                itemStyle: {
                                    normal: {
                                        label: {
                                            show: true,
                                            position: 'center',
                                            formatter: '{b}',
                                            textStyle: {
                                                baseline: 'bottom'
                                            }
                                        },
                                        labelLine: {
                                            show: false
                                        }
                                    }
                                }

                            }
                        ]
                    },
                    {
                        type: 'pie',
                        center: ['70%', '50%'],
                        radius: [40, 60],
                        x: '60%', // for funnel
                        itemStyle: {
                            normal: {
                                label: {
                                    formatter: function (params) {
                                        return 100 - params.value + '%'
                                    },
                                    textStyle: {
                                        baseline: 'top'
                                    }
                                }
                            },
                        },
                        data: [
                            {
                                name: 'other',
                                value: 99.5,
                                itemStyle: {
                                    normal: {
                                        color: '#1bb2d8',
                                        label: {
                                            show: true,
                                            position: 'center'
                                        },
                                        labelLine: {
                                            show: false
                                        }
                                    },
                                    emphasis: {
                                        color: 'rgba(0,0,0,0)'
                                    }
                                }
                            },
                            {
                                name: '差评率',
                                value: 1.9,
                                itemStyle: {
                                    normal: {
                                        label: {
                                            show: true,
                                            position: 'center',
                                            formatter: '{b}',
                                            textStyle: {
                                                baseline: 'bottom'
                                            }
                                        },
                                        labelLine: {
                                            show: false
                                        }
                                    }
                                }

                            }
                        ]
                    }
                ]
            };
            var chart_ele = document.getElementById("averagePraiseChart");
            var averagePraiseChart = echarts.init(chart_ele, theme);
            averagePraiseChart.setOption(option);

            $rootScope.$on('switchType', function (e, type) {
                /*for (var i = 0; i < optionData.averagePraiseOptions.length; i++) {
                 if (optionData.averagePraiseOptions[i].name == type) {
                 option = optionData.averagePraiseOptions[i].option;
                 }
                 }*/
                averagePraiseChart.setOption(option);
            });

            scope.fullscreen = function () {
                $rootScope.$broadcast('fullscreen', option);
            }
        },
        template: '<div class="w h"><div id = "averagePraiseChart" class="w h"></div><div class = "full-screen right-bottom-pos" ng-click = "fullscreen()"></div></div>'
    }
}]);
//商品总类数与销量统计
MAIN.directive("productsNumberChart", ["$rootScope", "tools", function ($rootScope, tools) {
    return {
        restrict: 'AE',
        scope: {},
        replace: true,
        link: function (scope, element, attrs) {
            var option;
            var chart_ele = document.getElementById("productNumberChart");
            var productNumberChart = echarts.init(chart_ele, theme);
            if (tools.datasource) {
                tools.get({
                    url: '/Intelligence-Business-Management/getChartByModuleId.htm',
                    data: {
                        uuid: '69341649-c33d-4fd3-b6d1-7d264df7c8b0',
                        moduleId: 1316113034000,
                        moduleType: 'chart'
                    },
                    succ: function (resp) {
                        if (resp.success) {
                            option = resp.value.option;
                            option.title = {
                                text: '2016年' + tools.town() + '县各镇商品总类数与销量统计',
                                x: 'left'
                            };
                            // option.legend = {
                            //     x:'right',
                            //     y:'top',
                            //     data :resp.value.option.legend.data
                            // };

                            option.yAxis = [
                                {
                                    type: 'value',
                                    axisLabel: {
                                        textStyle: {
                                            color: '#fff'
                                        }
                                    }
                                }
                            ];
                            angular.forEach(option.xAxis[0].data, function (item, index) {
                                option.xAxis[0].data[index] = {value: item, textStyle: {color: '#fff'}};
                            });
                            option.toolbox.show = false;
                            option.legend.show = false;
                            option.series[0].itemStyle = {};
                            option.series[1].itemStyle = {};
                            productNumberChart.setOption(option);
                        }
                    }
                });
            } else {
                var datas = {
                    town: [
                        {
                            name: '商品总数',
                            type: 'bar',
                            data: [2000, 2863, 3000, 2500, 3963, 4000, 6345]
                        },
                        {
                            name: '成交量',
                            type: 'bar',
                            data: [1693, 1485, 2536, 1536, 2000, 2639, 4523]
                        }
                    ],
                    village: [
                        {
                            name: '商品总数',
                            type: 'bar',
                            data: [2563, 9636, 7539, 9666, 4000, 3320, 9635]
                        },
                        {
                            name: '成交量',
                            type: 'bar',
                            data: [1853, 2563, 1425, 4523, 2000, 2639, 1258]
                        }
                    ],
                    industry: [
                        {
                            name: '商品总数',
                            type: 'bar',
                            data: [2639, 2582, 4256, 6666, 5236, 7412, 2692]
                        },
                        {
                            name: '成交量',
                            type: 'bar',
                            data: [1520, 1132, 3101, 5134, 4590, 4325, 1210]
                        }
                    ]
                }
                option = {
                    title: {
                        text: '2016年' + tools.town() + '县各镇商品总数与成交量统计',
                        x: 'left'
                    },
                    tooltip: {
                        trigger: 'axis'
                    },
                    legend: {
                        data: ['成交量', '商品总数'],
                        x: 'right'
                    },
                    calculable: true,
                    xAxis: [
                        {
                            type: 'category',
                            data: tools.towns().slice(0, 6),
                            axisLabel: {
                                textStyle: {
                                    color: '#fff'
                                }
                            }
                        }
                    ],
                    yAxis: [
                        {
                            type: 'value',
                            axisLabel: {
                                textStyle: {
                                    color: '#fff'
                                }
                            }
                        }
                    ],
                    series: datas.town
                };
                productNumberChart.setOption(option);
                productNumberChart.on(echarts.config.EVENT.CLICK, function (param) {
                    option.title.text = '2016年' + param.name + '各村商品总数与成交量统计';
                    option.xAxis = [
                        {
                            type: 'category',
                            data: tools.villages().slice(0, 6),
                            axisLabel: {
                                textStyle: {
                                    color: '#fff'
                                }
                            }
                        }
                    ];
                    option.series = datas.village;
                    productNumberChart.setOption(option);
                });

                $rootScope.$on('switchType', function (e, type) {
                    if (type == 'town') {
                        option.xAxis[0].data = tools.towns().slice(0, 6);
                    } else if (type == 'village') {
                        option.xAxis[0].data = tools.villages().slice(0, 6);
                    } else {
                        option.xAxis[0].data = tools.industrys().slice(0, 6);
                    }
                    option.series = datas[type];
                    productNumberChart.setOption(option);
                });
            }

            scope.fullscreen = function () {
                $rootScope.$broadcast('fullscreen', option);
            }
        },
        template: '<div class="w h"><div id = "productNumberChart" class="w h"></div><div class = "full-screen right-bottom-pos" ng-click = "fullscreen()"></div></div>'
    }
}]);
//2016年本县各镇平均发单时间统计
MAIN.directive("sendsTimeChart", ["$rootScope", "tools", function ($rootScope, tools) {
    return {
        restrict: 'AE',
        scope: {},
        replace: true,
        link: function (scope, element, attrs) {
            var datas = {
                town: [0.5, 1, 2, 2.4, 1.6, 1.5, 1.8, 0.4],
                village: [2.3, 1.6, 2.4, 0.6, 3.0, 0.1, 2, 1],
                industry: [0.5, 0.52, 1.3, 2.5, 1.8, 1.5, 3, 5]
            };
            var option = {
                title: {
                    text: '2016年' + tools.town() + '县各镇平均发单时间统计',
                    x: 'center'
                },
                tooltip: {
                    trigger: 'axis'
                },
                calculable: true,
                xAxis: [
                    {
                        type: 'category',
                        data: tools.towns().slice(0, 6),
                        axisLabel: {
                            textStyle: {
                                color: '#fff'
                            }
                        }
                    }
                ],
                yAxis: [
                    {
                        type: 'value',
                        name: '发单时间（单位:天）',
                        axisLabel: {
                            textStyle: {
                                color: '#fff'
                            }
                        }
                    }
                ],
                series: [
                    {
                        type: 'bar',
                        stack: '总量',
                        data: datas.town,
                        markLine: {
                            data: [
                                {type: 'average', name: '平均值'}
                            ]
                        }
                    }
                ]
            }
            var chart_ele = document.getElementById("sendTimeChart");
            var sendTimeChart = echarts.init(chart_ele, theme);
            sendTimeChart.setOption(option);

            sendTimeChart.on(echarts.config.EVENT.CLICK, function (param) {
                option.title.text = '2016年' + param.name + '各村平均发单时间统计';
                option.xAxis = [
                    {
                        type: 'category',
                        data: tools.villages().slice(0, 6),
                        axisLabel: {
                            textStyle: {
                                color: '#fff'
                            }
                        }
                    }
                ];
                option.series[0].data = datas.village;
                sendTimeChart.setOption(option);
            });

            $rootScope.$on('switchType', function (e, type) {
                if (type == 'town') {
                    option.xAxis[0].data = tools.towns().slice(0, 6);
                } else if (type == 'village') {
                    option.xAxis[0].data = tools.villages().slice(0, 6);
                } else {
                    option.xAxis[0].data = tools.industrys().slice(0, 6);
                }
                option.series[0].data = datas[type];
                sendTimeChart.setOption(option);
            });

            scope.fullscreen = function () {
                $rootScope.$broadcast('fullscreen', option);
            }
        },
        template: '<div class="w h"><div id = "sendTimeChart" class="w h"></div><div class = "full-screen right-bottom-pos" ng-click = "fullscreen()"></div></div>'
    }
}]);